package com.qiuhui.controller;

import com.qiuhui.entity.Car;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @ClassName: CarController
 * @Description: TODO
 * @author: tian
 * @date: 2021/3/22  5:26 下午
 */
@Controller
public class CarController {
    /**
     * 方式一：域名和方法参数一致
     * http://localhost:8080/brand?brand=Ferrari
     */
    @RequestMapping("/brand")
    public String carBrand(String brand, Model model) {
        System.out.println(brand);
        model.addAttribute("content", brand);
        return "car";
    }

    /**
     * 方式二：域名和方法参数不一致
     * http://localhost:8080/country?couName=usa
     */
    @RequestMapping("/country")
    public String carCountry(@RequestParam("couName") String country, Model model) {
        System.out.println(country);
        model.addAttribute("content", country);
        return "car";
    }

    /**
     * 方式三：参数为一个实体类
     * http://localhost:8080/car?brand=ferrari  -->  Car(brand=ferrari, Country=null, price=0)
     * http://localhost:8080/car?brand=ferrari&country=italy&price=20000  -->  Car(brand=ferrari, Country=italy, price=20000)
     */
    @RequestMapping("/car")
    public String carInfo(Car car, Model model) {
        System.out.println(car);
        model.addAttribute("content", car);
        return "car";
    }
}
